<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TestApi</title>
</head>
<body>
    <input type="text" id="text">
    <button id="submit">提交</button>
    <script>
        let webSocket = new WebSocket("ws://127.0.0.1:8080/test");
        webSocket.onopen = function(){
            console.log("建立连接")
        }
        webSocket.onmessage = function(body){
            console.log("收到信息" + body);
        }
        webSocket.onerror = function(){
            console.log("出现错误");
        }
        webSocket.onclose = function(){
            console.log("断开连接");
        }
        let input = document.querySelector("#text");
        let button = document.querySelector("#submit");
        button.onclick = function(){
            webSocket.send(input.value);
        }
    </script>
</body>
</html>